package com.sky.mapper;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface OrdersMapper {
    void insert(Orders order);

    void insertBatchOrderDetail(List<OrderDetail> orderDetails);

    @Update("update orders set pay_status = #{payStatus} , status = #{status} , checkout_time = #{checkoutTime},rejection_reason = #{rejectionReason},cancel_reason = #{cancelReason},cancel_time = #{cancelTime} where id = #{id}")
    void updateOrder(Orders order);

//    @Select("select * from orders  where orders.user_id = #{userId}")
    List<Orders> getOrdersByUserId(Long userId, Integer status);

    @Select("select * from order_detail where order_id = #{orderId}")
    List<OrderDetail> getOrderDetailByOrderId(Long orderId);

    @Select("select * from orders where id = #{id}")
    Orders getOrdersByOrderId(Long id);

    List<Orders> getOrdersByCondition(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select count(*) from orders where status = #{status}")
    Integer getStatusStatistics(Integer status);
}
